var jeslee = {

   params: {
      rootDir: "/",
      debug_enabled: true,
      previousModelNr: ''
   },

   init : function (rootDir) {
      jeslee.initLog();
      if (rootDir !== undefined) {
         jeslee.params.rootDir = rootDir + "/";
      }
      // hide all impression should be display when clicked on
      jeslee.hideImpressions();
      // initialize stardust
      if ($.support.opacity)
      {
         jpan.stardust({'spriteImage':jeslee.params.rootDir + 'js/jpan/gfx/stardust.png'});
      }
      // initialize poof effect
      $('.jpan-poof').click(function(event) {
         jpan.animatePoof(event, {'spriteImage':myRootDir + 'js/jpan/gfx/poof.png'});
      });
      // add click event to display contact info
      $("#menu-top-menu a[title='contact']").toggle(jeslee.showContactForm, jeslee.hideContactForm);
      // add click event to model-impression buttons
      $(".menu-model-impression").click(function(event) {
         jeslee.handleModelImpressionClick(event,this);
      });
      // show first model impression
      $('#menu-model-impression-01').trigger('click');
      jeslee.showRandomPageImpression();
   },
   showContactForm: function(event) {
      event.preventDefault();
      $("#contactInfo").slideDown();
   },
   hideContactForm: function(event) {
      event.preventDefault();
      $("#contactInfo").slideUp();
   },
   hideImpressions: function() {
      $("#model-impressions .model").hide();
   },
   handleModelImpressionClick: function(event, menuItem)
   {
      event.preventDefault();
      if (!$(menuItem).hasClass("selected"))
      {
         $(".menu-model-impression").removeClass("selected");
         $(menuItem).addClass("selected");
         var menuId = $(menuItem).attr("id");
         jeslee.showModelImpression(menuId.substring(menuId.length-2, menuId.length));
      }
   },
   showModelImpression: function(modelNr) {
      $("#model-"+jeslee.params.previousModelNr).fadeOut(1000);
      $( "#model-"+modelNr).fadeIn(1000);
      //setTimeout("$('#model-"+modelNr+"').fadeIn(1000)", 0);
      jeslee.params.previousModelNr = ''+modelNr;
   },
   showModelImpressionOud: function(modelNr) {
      if (!$("#model-impression-spot").exists())
      {
         $("#model-impressions").prepend('<div id="model-impression-spot"></div>');
         fadeIn();
      }
      else
      {
         $("#model-impression-spot").fadeOut(1000, fadeIn);
      }
      function fadeIn()
      {
//         $("#model-impression-spot").clean();
         $("#model-impression-spot").html($("#model-"+modelNr).html());
//         $("#model-impression-spot").append($("#model-impression-"+modelNr).html());
         $("#model-impression-spot").fadeIn(1000);
      }
   },
   showRandomPageImpression: function() {
      var pageImpression = [
         '/images/model/model-Yvon-small.png',
         '/images/model/model-Jessy-small.png',
         '/images/model/model-Frida-small.png',
         '/images/model/model-Diede-small.png'
      ];
      var randomIndex = Math.floor(Math.random() * pageImpression.length);
      $('.random-model .impression').attr('src',jeslee.params.rootDir + pageImpression[randomIndex]);
   },

   // utility functions
   log: function() {/* default noop */
   },
   initLog: function() {
      if (jeslee.params.debug_enabled && typeof window.console !== 'undefined') {
         jeslee.log = function(msg) {
            window.console.debug(msg);
         };
      }
   }
};

/**
 * add exists funtion to jquery. It returns 'true' if and element is found otherwise false is returned.
 */
jQuery.fn.exists = function()
{
 return jQuery(this).length > 0;
};
